#include "individual.h"

Individual::Individual()
{
}


QString Individual::getStrata( QString key ) {
    if( _strata.keys().contains( key ) )
        return _strata[key];
    else
        return QString("");
}

qreal Individual::getSpatial( QString key ) {
    if( _spatial.keys().contains( key ) )
        return _spatial[key];
    else
        return 0.0;
}

qreal Individual::getExternal( QString key ) {
    if( _external.keys().contains( key ) )
        return _external[key];
    else
        return 0.0;
}

Locus* Individual::getLocus(QString key) {
    if( _loci.keys().contains(key))
        return _loci[key];
    else
        return new Locus();
}

QString Individual::getData( QString key ) {
    if( _strata.keys().contains( key ) )
        return getStrata( key );
    else if( _spatial.keys().contains(key))
        return QString("%1").arg( getSpatial( key ) );
    else if( _external.keys().contains(key))
        return QString("%1").arg( getExternal( key ) );
    else if( _loci.keys().contains(key))
        return QString("%1").arg( getLocus( key )->toString() );
    else
        return QString("");
}

QStringList Individual::strataNames() {
    QStringList ret = _strata.keys();
    ret.sort();
    return ret;
}

QStringList Individual::spatialNames() {
    QStringList ret = _spatial.keys();
    ret.sort();
    return ret;
}

QStringList Individual::externalNames() {
    QStringList ret = _external.keys();
    ret.sort();
    return ret;
}

QStringList Individual::locusNames() {
    QStringList ret = _loci.keys();
    ret.sort();
    return ret;
}



QString Individual::toString() {
    QString ret = "";
    QStringList keys;

    keys = _strata.keys();
    keys.sort();
    foreach(QString key, keys)
        ret += QString("%1,").arg(_strata[key]);

    keys = _spatial.keys();
    keys.sort();
    foreach(QString key, keys)
        ret += QString("%1,").arg(_spatial[key]);

    keys = _external.keys();
    keys.sort();
    foreach(QString key, keys)
        ret += QString("%1,").arg(_external[key]);

    keys = _loci.keys();
    keys.sort();
    foreach(QString key, keys)
        ret += QString("%1,").arg(_loci[key]->toString());

    if( ret.isEmpty())
        return ret;
    else
        return ret.left(ret.length()-1);
}
